home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 501-525 / disk_503 / pcq / pcq12asc.lzh / Source / Pascal.i < prev    next >
Text File  |  1991-04-10  |  10KB  |  330 lines

  1. {
  2.     Pascal.i (of PCQ Pascal)
  3.     Copyright (c) 1989 Patrick Quaid.
  4.  
  5.     These are the constants, types and variables required
  6. for the compiler.
  7.  
  8. }
  9.  
  10.  
  11. CONST
  12.  
  13.     Hash_Size    = 255;        { Size of the Hash Table - 1 }
  14.     literalsize    = 8000;        { room for character literals }
  15.  
  16.     eqsize        = 127;        { size of the error buffer }
  17.  
  18.     BufferSize    = 2048;        { size of Input buffer }
  19.     BufferMax    = BufferSize - 1; { Last index in Buffer }
  20.  
  21.     Spell_Max    = 10000;    { Size of the spelling records }
  22.  
  23.     MaxExprNodes    = 255;        { Pre-allocated nodes }
  24.  
  25.     MaxCode        = 4096;        { Last code position + 1 }
  26.  
  27.  
  28. {
  29.     These are the symbols.  Note that the first 40 or so
  30. correspond to the appropriate entries in the Reserved array.
  31. }
  32.  
  33. TYPE
  34.     Symbols = (and1, array1, begin1, by1, case1,
  35.         const1, div1, do1, downto1, else1, end1, extern1,
  36.         file1, for1, forward1, func1, goto1, if1, in1,
  37.         label1, mod1, not1, of1, or1, packed1, private1,
  38.         proc1, program1, record1, repeat1, return1, set1,
  39.         shl1, shr1, then1, to1, type1, until1, var1, while1,
  40.         with1, xor1,
  41.  
  42.         ident1, numeral1, asterisk1, becomes1, colon1,
  43.         comma1, dotdot1, endtext1, equal1, greater1,
  44.         leftbrack1, leftparent1, less1, minus1,
  45.         notequal1, notgreater1, notless1, period1, plus1,
  46.         rightbrack1, rightparent1, semicolon1, leftcurl1,
  47.         rightcurl1, quote1, apostrophe1, carat1, at1, pound1,
  48.         ampersand1, realdiv1, realnumeral1, unknown1, Char1,
  49.         int2real, real2int, short2long, byte2short, byte2long,
  50.         stanfunc1, field1);
  51.  
  52. CONST
  53.     LastReserved = Xor1;
  54.  
  55. TYPE
  56.  
  57.     OpCodes = (op_ADD, op_ADDA, op_ADDQ, op_AND, op_ASL, op_ASR,
  58.         op_BEQ, op_BGE, op_BGT, op_BLE, op_BLT,
  59.         op_BNE, op_BPL, op_BRA, op_BSET, op_CLR,
  60.         op_CMP, op_CNOP, op_DBRA, op_DC, op_DIVS,
  61.         op_DS, op_END, op_EOR, op_EXG, op_EXT,
  62.         op_JSR, op_LEA, op_LINK, op_LSL, op_LSR,
  63.         op_MOVE, op_MOVEM, op_MOVEQ, op_MULS,
  64.         op_NEG, op_NOT, op_OR, op_PEA, op_POP, op_PUSH,
  65.         op_RESTORE, op_RTS, op_SAVE, op_SECTION, op_SEQ,
  66.         op_SGE, op_SGT, op_SLE, op_SLT, op_SNE, op_SUB,
  67.         op_SUBA, op_SUBQ, op_SWAP, op_TRAP, op_TST, op_UNLK,
  68.         op_XDEF, op_XREF, op_None, op_LABEL, op_EOF);
  69.  
  70.  
  71.                  {_____e.g.___________extension__________}
  72.  
  73.     EAModes = (    ea_Constant,    { #nnnn        value of constant }
  74.         ea_Absolute,    { nnnn        value of constant }
  75.         ea_Literal,    { #LitLab+nnnn    offset into table }
  76.         ea_Global,    { _globalname    address of ID }
  77.         ea_Address,    { #_globalname    address of ID }
  78.         ea_Index,    { d16(An)    offset value }
  79.         ea_String,    { "_p%acos"    address of string }
  80.         ea_Label,    { _p%nnn    label number }
  81.         ea_RegInd,    { d8(An,Dm.l)    d8 shl 8 or Dm }
  82.         ea_RegList,    { Rn/Rm/...    Mask of registers 0..15 }
  83.         ea_Offset,    { #_global+nnn    ID pointer, then offset }
  84.         ea_Indirect,    { (An)        none }
  85.         ea_PostInc,    { (An)+        none }
  86.         ea_PreDec,    { -(An)        none }
  87.         ea_Register,    { Rn        none }
  88.         ea_None        { not used    none }
  89.           );
  90.  
  91.     TypeObject = (ob_array, ob_set, ob_record, ob_ordinal, ob_pointer,
  92.          ob_enumer, ob_subrange, ob_synonym, ob_file, ob_real);
  93.  
  94.     TypeRec = Record
  95.     Next    : ^TypeRec;
  96.     Object  : TypeObject;
  97.     SubType    : ^TypeRec;
  98.     Ref    : Address; { An IDPtr to record fields, or
  99.                  a TypePtr to the index type of an array }
  100.     Upper,
  101.     Lower    : Integer;
  102.     Size    : Integer;
  103.     end;
  104.     TypePtr = ^TypeRec;
  105.  
  106.     IDObject = (global, local, refarg, valarg, proc, func, obtype, field,
  107.         stanproc, stanfunc, constant, pending_type, typed_const,
  108.         lab);
  109.  
  110.     IDStorage = (st_none, st_external, st_internal, st_private, st_initialized,
  111.          st_forward);
  112.  
  113.     IDRec = Record
  114.     Next    : ^IDRec;
  115.     Name    : String;
  116.     Object    : IDObject;
  117.     VType    : TypePtr;
  118.     Param    : ^IDRec;
  119.     Level    : Short;
  120.     Storage    : IDStorage;
  121.     Offset    : Integer;
  122.     Unique    : Integer;
  123.     end;
  124.     IDPtr = ^IDRec;
  125.  
  126.     BlockRec = Record
  127.     Previous : ^BlockRec;
  128.     FirstType: TypePtr;
  129.     Level     : Short;
  130.     Table     : Array [0..Hash_Size] of IDPtr;
  131.     end;
  132.     BlockPtr = ^BlockRec;
  133.  
  134. { The expression types.  The first one declares the normal expression
  135.   node, and is used extensively throughout Expression.p and Generate.p.
  136.   The second is just an enumeration of the register names, which is
  137.   used mainly in Generate.p. }
  138.  
  139.     ExprNode = record
  140.         Kind  : Symbols;    { operator, var1, type1, etc. }
  141.         Used  : Boolean;    { currently allocated }
  142.         Next,            { list of parameter expressions }
  143.         Left,            { Left expression, or only if unary op }
  144.         Right : ^ExprNode;    { Right side of expression }
  145.         EType : TypePtr;    { Result type of the expression }
  146.     Value : Integer;    { constant value or ID Ptr }
  147.     end;
  148.     ExprPtr = ^ExprNode;
  149.  
  150.     Regs = (d0,d1,d2,d3,d4,d5,d6,d7,a0,a1,a2,a3,a4,a5,a6,a7);
  151.  
  152.     RegName = Array [0..1] of Char;
  153.  
  154. { The following record allows me to nest include calls to the
  155.   limits of memory. }
  156.  
  157.     FileRec = Record
  158.     PCQFile    : Text;
  159.     Previous: ^FileRec;
  160.     SaveLine,
  161.     SaveStart : Integer;
  162.     SaveChar  : Char;
  163.     Name    : String;
  164.     end;
  165.     FileRecPtr = ^FileRec;
  166.  
  167. { The next record saves the names of include files so I won't load
  168.   them twice.  Note that only as much of the record as is required
  169.   for a particular file name is allocated. }
  170.  
  171.     IncludeRec = record
  172.     Next : ^IncludeRec;
  173.     Name : Array [0..100] of Char;
  174.     end;
  175.     IncludeRecPtr = ^IncludeRec;
  176.  
  177. { This next record helps implement the With statement.  For each active
  178.   with statement, there is a corresponding record.  These are stacked
  179.   (to handle scoping), and simply contain a pointer to the proper type. }
  180.  
  181.     WithRec = Record
  182.           Previous : ^WithRec;
  183.           RecType  : TypePtr;
  184.           Offset   : Integer;
  185.           end;
  186.     WithRecPtr = ^WithRec;
  187.  
  188. {    This is the spelling table stuff.  Originally I was allocating
  189.     memory for ID names one at a time, then freeing them at the end of
  190.     a procedure definition.  I was probably wasting too much time allocating
  191.     memory, however, so I switched back to a one-big-array method, although
  192.     this is somewhat more flexible than the 1.0 version. }
  193.  
  194.     SpellRec = Record
  195.            Previous : ^SpellRec;
  196.            First : Integer; { The first index held in this record }
  197.            Data  : Array [0..Spell_Max] of Char;
  198.            end;
  199.     SpellRecPtr = ^SpellRec;
  200.  
  201. CONST
  202.     RN : Array [d0..a7] of RegName = (    'd0','d1','d2','d3',
  203.                     'd4','d5','d6','d7',
  204.                     'a0','a1','a2','a3',
  205.                     'a4','a5','a6','sp');
  206.  
  207.     Extensions : Array [ea_Constant..ea_None] of Byte =
  208.                     (1,1,1,1,1,1,1,1,1,1,2,0,0,0,0,0);
  209.  
  210.     OpText : Array [op_ADD..op_LABEL] of String = (
  211.         "add", "adda", "addq", "and", "asl", "asr",
  212.         "beq", "bge", "bgt", "ble", "blt",
  213.         "bne", "bpl", "bra", "bset", "clr",
  214.         "cmp", "cnop", "dbra", "dc", "divs",
  215.         "ds", "end", "eor", "exg", "ext",
  216.         "jsr", "lea", "link", "lsl", "lsr",
  217.         "move", "movem", "moveq", "muls",
  218.         "neg", "not", "or", "pea", "pop", "push",
  219.         "restore", "rts", "save", "section", "seq",
  220.         "sge", "sgt", "sle", "slt", "sne", "sub",
  221.         "suba", "subq", "swap", "trap", "tst", "unlk",
  222.         "xdef", "xref", "none", "Label");
  223.  
  224.  
  225. VAR
  226.  
  227. {
  228.     These are the global variables for the compiler.
  229. When this file is included by the main program, space is
  230. allocated for the variables.  The external files, although
  231. they also import this file, just generate external
  232. references.
  233. }
  234.  
  235.     CurrentBlock    : BlockPtr;
  236.  
  237. { Space for literal strings and arrays in the program text }
  238.  
  239.     LitQ        : Array [0..LiteralSize] of Char;
  240.     LitPtr        : Integer;
  241.  
  242. { The reserved words, held here in order to make searching quicker }
  243.  
  244.     Reserved    : Array [And1..LastReserved] of String;
  245.  
  246. { These four implement the error queue, which prints out the latest
  247. 128 chars or two lines, whichever is less, when an error occurs }
  248.  
  249.     ErrorQ        : Array [0..EQSize] of Char;
  250.     EQStart        : Short;
  251.     EQEnd        : Short;
  252.     ErrorPtr    : Short;
  253.  
  254. { The spelling table variables }
  255.  
  256.     CurrentSpellRec : SpellRecPtr;
  257.     SpellPtr    : Integer;
  258.  
  259. { The With variables }
  260.  
  261.     FirstWith,
  262.     LastWith    : WithRecPtr;
  263.     StackLoad    : Integer;
  264.  
  265. { Expression evaluation variables }
  266.  
  267.     UsedRegs    : Integer;    { Bit map of registers in use }
  268.  
  269.     MathLoaded    : Boolean;    { Is FP math library address in a6? }
  270.  
  271. { Register allocation counters }
  272.  
  273.     NextDataRegister : Regs;
  274.     NextAddressRegister : Regs;
  275.  
  276. { Expression node management }
  277.  
  278.     ExpressionNodeStore : Array [0..MaxExprNodes] of ExprNode;
  279.     NextFreeExprNode    : Integer;
  280.  
  281. { Code table management }
  282.  
  283.     Code_Table    : ^Array [0..MaxInt] of Integer;
  284.                     { Table of coded instructions }
  285.     NextCode    : Integer;    { Position in Code_Table for next }
  286.  
  287.  
  288.     StandardStorage    : IDStorage;    { The default storage mode }
  289.     NxtLab        : Integer;    { Just the current label }
  290.     LitLab        : Integer;    { Label of the literals }
  291.     StackSpace    : Integer;    { Counts local var stack space }
  292.     ErrorCount    : Integer;    { Literally the # of errors }
  293.     InFile        : FileRecPtr;    { The current input record }
  294.     OutFile        : Text;        { The main assembly output }
  295.     MainMode    : Boolean;    { Is this a program file? }
  296.     IncludeList    : IncludeRecPtr;{ list of include files }
  297.     FnStart        : Integer;    { The line # of the start of this }
  298.     LineNo        : Integer;    { Current line number. }
  299.  
  300.     CurrFn        : IDPtr;    { Index of current proc or func }
  301.     BadType,            { Universal type index }
  302.     IntType,            { These are just pointers to }
  303.     BoolType,            { the appropriate types }
  304.     RealType,
  305.     CharType,
  306.     TextType,
  307.     StringType,
  308.     AddressType,
  309.     ShortType,
  310.     ByteType,
  311.     LiteralType    : TypePtr;    { Temp type for array lits }
  312.     CurrSym        : Symbols;    { Current symbol }
  313.     SymLoc        : Integer;    { Literal integer }
  314.     RealValue    : Real;        { Literal float }
  315.     SymText        : String;    { Holds ident. text }
  316.     CurrentChar    : Char;        { The current char! }
  317.     BuffedChar    : Char;        { Buffered character }
  318.     CharBuffed    : Boolean;    { is a char buffered? }
  319.     RangeCheck    : Boolean;    { Doing rangechecks? }
  320.     IOCheck        : Boolean;    { Doing IO checks? }
  321.     Inform        : Boolean;    { Verbose updates? }
  322.     DoReport    : Boolean;    { Reporting Expr Trees }
  323.     ShortCircuit    : Boolean;    { Do short circuit evaluations }
  324.     SmallInitialize    : Boolean;    { Link in small initialize code }
  325.     StdOut_Interactive : Boolean;    { stdout is a console }
  326.     ConstantExpression : Boolean;    { True => Typed constants become constants }
  327.     MainName    : String;    { Main file name }
  328.     OutName        : String;    { The output file name }
  329.     TypeID        : IDPtr;    { Points to a type's ID rec }
  330.